package design.patterns.creational.singleton.lazy.v4;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/4/1 10:32
 */

import design.patterns.creational.singleton.MyThread;

/**
 * 懒汉式 静态内部类实现单例
 */
public class LazySingleton {

    private LazySingleton(){

    }
    //静态类一般在第一次加载是初始化
    public static class InnerClass{
        private static LazySingleton lazySingleton = new LazySingleton();
    }

    public static LazySingleton getInstance(){
        return  InnerClass.lazySingleton;
    }

}


class Test {
    public static void main(String[] args) {
        //单线程测试
       /* LazySingleton instance = LazySingleton.getInstance();
        System.out.println(instance);

        LazySingleton instance2 = LazySingleton.getInstance();
        System.out.println(instance2);*/
        //多线程测试
        int count = 800;
        for (int i = 0; i < count; i++) {
            MyThread t1 = new MyThread();
            t1.start();

        }
        System.out.println("main....");

    }
}
